package com.aplink.generic.pojo.controlspec.menu;

import android.content.pm.PackageManager.NameNotFoundException;
import android.text.TextUtils;
import android.view.View;

import com.aplink.generic.GenericFragment;
import com.aplink.generic.constant.type.MenuShowAsActionType;
import com.aplink.generic.pojo.GenericObject;
import com.aplink.generic.pojo.controlspec.ControlSpec;
import com.aplink.generic.util.ResourcesHelper;
import com.aplink.generic.util.objectrule.Target;
import com.aplink.generic.util.objectrule.TargetCollection;
import com.aplink.generic.util.validation.LocationValidation;

public class MenuItemSpec extends ControlSpec {
	private static final long serialVersionUID = 7472767460772466369L;
	private String mContentData;
	private String mFormDesign;
	private transient GenericObject mGenericObject;
	private String mIcon;
	private LocationValidation mLocationValidation;
	private int mOrderInCategory;
	private MenuShowAsActionType mShowAsActionType;
	private TargetCollection mTargetCollection;
	private String mTitle;

	public String getContentData() {
		return this.mContentData;
	}

	public int getContentDataID() {
		return ResourcesHelper.getRawIdByName(this.mContentData);
	}

	public String getFormDesign() {
		return this.mFormDesign;
	}

	public int getFormDesignID() {
		return ResourcesHelper.getRawIdByName(this.mFormDesign);
	}

	public GenericObject getGenericObject() {
		return this.mGenericObject;
	}

	public String getIcon() {
		return this.mIcon;
	}

	public int getIconID() {
		if (TextUtils.isEmpty(this.mIcon)) {
			return 0;
		}
		return ResourcesHelper.getDrawableIdByName(this.mIcon);
	}

	@Override
	public int getIDValue() {
		return View.NO_ID;
	}

	public LocationValidation getLocationValidation() {
		return mLocationValidation;
	}

	public int getOrderInCategory() {
		return this.mOrderInCategory;
	}

	public MenuShowAsActionType getShowAsActionType() {
		return this.mShowAsActionType;
	}

	public TargetCollection getTargetCollection() {
		return this.mTargetCollection;
	}

	public String getTitle() {
		return this.mTitle;
	}

	public void linkToNextPage(final GenericFragment genericFragment)
	        throws InstantiationException, IllegalAccessException,
	        ClassNotFoundException, NameNotFoundException {
		final Target targetActivity = this.mTargetCollection
		        .getTargetClass(this.mGenericObject);
		genericFragment.startActivity(targetActivity.getTargetClass(),
		        targetActivity.getPassingValue(), this.mGenericObject);
	}

	public void setContentData(final String contentData) {
		this.mContentData = contentData;
	}

	public void setFormDesign(final String formDesign) {
		this.mFormDesign = formDesign;
	}

	public void setGenericObject(final GenericObject genericObject) {
		this.mGenericObject = genericObject;
	}

	public void setIcon(final String icon) {
		this.mIcon = icon;
	}

	public void setLocationValidation(
	        final LocationValidation locationValidation) {
		mLocationValidation = locationValidation;
	}

	public void setOrderInCategory(final int orderInCategory) {
		this.mOrderInCategory = orderInCategory;
	}

	public void setShowAsActionType(final MenuShowAsActionType showAsActionType) {
		this.mShowAsActionType = showAsActionType;
	}

	public void setTargetCollection(final TargetCollection targetCollection) {
		this.mTargetCollection = targetCollection;
	}

	public void setTitle(final String title) {
		this.mTitle = title;
	}
}
